package com.dizner.imagepickertest;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.dizner.dimagepicker.DImagePicker;
import com.dizner.dimagepicker.Image;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    private int REQUEST_CODE = 9;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.btn_pick_img).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DImagePicker.with(MainActivity.this).max(1).requestCode(REQUEST_CODE).launch();
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) {
            List<Image> images = DImagePicker.outResult(data);
            showToast("" + images.size());
        }
    }

    private void showToast(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }

}
